package com.betty.cscams.service.impl;

import java.util.Date;
import java.util.List;

import com.betty.cscams.common.page.MybatisPageHelper;
import com.betty.cscams.common.page.PageRequest;
import com.betty.cscams.common.page.PageResult;
import com.betty.cscams.util.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import com.betty.cscams.entity.SysNotice;
import com.betty.cscams.dao.SysNoticeMapper;
import com.betty.cscams.service.SysNoticeService;

/**
 * ---------------------------
 *  (SysNoticeServiceImpl)         
 * ---------------------------
 * 时间：  2022-03-16 20:41:54
 * ---------------------------
 */
@Service
public class SysNoticeServiceImpl implements SysNoticeService {

	@Autowired
	private SysNoticeMapper sysNoticeMapper;


	@Override
	public int save(SysNotice record) {
		record.setLastUpdateBy(SecurityUtils.getUsername());
		record.setLastUpdateTime(new Date());
		if(record.getId() == null || record.getId() == 0) {
			record.setCreateBy(SecurityUtils.getUsername());
			record.setCreateTime(new Date());
			record.setStatus(1);
			return sysNoticeMapper.add(record);
		}
		return sysNoticeMapper.update(record);
	}

	@Override
	public int delete(SysNotice record) {
		return sysNoticeMapper.delete(record.getId());
	}

	@Override
	public int delete(List<SysNotice> records) {
		for(SysNotice record:records) {
			delete(record);
		}
		return 1;
	}

	@Override
	public SysNotice findById(Long id) {
		return sysNoticeMapper.findById(id);
	}

	@Override
	public PageResult findPage(PageRequest pageRequest) {
		Object name = pageRequest.getParam("name");
		Object status = pageRequest.getParam("status").toString();
		return  MybatisPageHelper.findPage(pageRequest, sysNoticeMapper,"findPage",name,status);

	}

	@Override
	public List<SysNotice> findList() {
		return sysNoticeMapper.findList();
	}

	@Override
	public List<SysNotice> findListByLimit(Integer limit) {
		return  sysNoticeMapper.findListByLimit(limit);
	}
}
